#include <iostream>
#include <vector>
using namespace std;

vector<vector<int> > res;
vector<vector<int> > ans;
vector<int> tmp(2,0);
void backtrace(vector<vector<int> >& maze,int cur,int j){
        if(cur >= maze.size() - 1 && j >= maze[0].size() - 1){
            res = ans;
            return;
        }
        if(maze[cur][j] == 1){
            return;
        }else{
            maze[cur][j] = 1;
        }
        if(j < maze[0].size() - 1){
            tmp[0] = cur;
            tmp[1] = j + 1;
            ans.push_back(tmp);
            backtrace(maze,cur,j + 1);
            ans.pop_back();
        }
        if(cur < maze.size() - 1){
            tmp[0] = cur + 1;
            tmp[1] = j ;
            ans.push_back(tmp);
            backtrace(maze,cur + 1,j);
            ans.pop_back();
        }
        if(cur > 0){
            tmp[0] = cur - 1;
            tmp[1] = j ;
            ans.push_back(tmp);
            backtrace(maze,cur - 1,j);
            ans.pop_back();
        }
        if(j > 0){
            tmp[0] = cur;
            tmp[1] = j - 1;
            ans.push_back(tmp);
            backtrace(maze,cur,j - 1);
            ans.pop_back();
        }
}

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int> > maze(n,vector<int>(m,0));

    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            cin>>maze[i][j];
        }
    }
    backtrace(maze,0,0);
    cout<<"("<<0<<","<<0<<")"<<endl;
    for(int i = 0;i < res.size();i++){
        cout<<"("<<res[i][0]<<","<<res[i][1]<<")"<<endl;
    }
    return 0;
}
